package filter;

import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.server.HandlerFilterFunction;
import org.springframework.web.reactive.function.server.HandlerFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

import javax.servlet.http.HttpServletRequest;

@Component
public class ExampleHandlerFilterFunction implements HandlerFilterFunction<ServerResponse, ServerResponse> {

    /**
     * 如果请求参数为pathVariable 且参数为test 就返回403
     */
    @Override
    public Mono<ServerResponse> filter(ServerRequest serverRequest, HandlerFunction<ServerResponse> handlerFunction) {
//        if (serverRequest.pathVariable("name").equalsIgnoreCase("test")) {
//            return ServerResponse.status(HttpStatus.FORBIDDEN).build();
//        }
        HttpServletRequest request = (HttpServletRequest) serverRequest;
//        request.getHeader("")
        return handlerFunction.handle(serverRequest);

    }

}